package com.hhl.flower.controller;

import com.hhl.flower.common.result.Result;
import com.hhl.flower.context.BaseContext;
import com.hhl.flower.pojo.vo.HistoryVO;
import com.hhl.flower.service.HistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/history")
@Api(tags = "历史相关接口")
@Slf4j
public class HistoryController {
	@Autowired
	private HistoryService historyService;

	@GetMapping("/list")
	@ApiOperation("查询用户所有的历史记录")
	public Result<List<HistoryVO>> list(){
		Integer currentId = BaseContext.getCurrentId();
		List<HistoryVO> fowerList = historyService.listHistoryFlowerOrderByTime(currentId);

		return Result.success(fowerList);
	}

	@PostMapping("/add")
	@ApiOperation("添加浏览记录")
	public Result add(@RequestParam("fid") Integer fid) {
		Integer userId = BaseContext.getCurrentId();

		historyService.addToHistory(userId, fid);

		return Result.success();
	}


}
